.class public Lcom/qiniu/utils/MultipartEntity;
.super Lorg/apache/http/entity/AbstractHttpEntity;
.source "MultipartEntity.java"


# annotations
.annotation system Ldalvik/annotation/MemberClasses;
    value = {
        Lcom/qiniu/utils/MultipartEntity$FileInfo;
    }
.end annotation


# instance fields
.field private fileTpl:Ljava/lang/String;

.field private mBoundary:Ljava/lang/String;

.field private mContentLength:J

.field private mData:Ljava/lang/StringBuffer;

.field private mFiles:Ljava/util/ArrayList;
    .annotation system Ldalvik/annotation/Signature;
        value = {
            "Ljava/util/ArrayList",
            "<",
            "Lcom/qiniu/utils/MultipartEntity$FileInfo;",
            ">;"
        }
    .end annotation
.end field

.field private mNotify:Lcom/qiniu/utils/IOnProcess;

.field private writed:J


# direct methods
.method public constructor <init>()V
    .registers 5

    .prologue
    .line 20
    invoke-direct {p0}, Lorg/apache/http/entity/AbstractHttpEntity;-><init>()V

    .line 14
    const-wide/16 v0, -0x1

    iput-wide v0, p0, Lcom/qiniu/utils/MultipartEntity;->mContentLength:J

    .line 15
    const-wide/16 v0, 0x0

    iput-wide v0, p0, Lcom/qiniu/utils/MultipartEntity;->writed:J

    .line 17
    new-instance v0, Ljava/lang/StringBuffer;

    invoke-direct {v0}, Ljava/lang/StringBuffer;-><init>()V

    iput-object v0, p0, Lcom/qiniu/utils/MultipartEntity;->mData:Ljava/lang/StringBuffer;

    .line 18
    new-instance v0, Ljava/util/ArrayList;

    invoke-direct {v0}, Ljava/util/ArrayList;-><init>()V

    iput-object v0, p0, Lcom/qiniu/utils/MultipartEntity;->mFiles:Ljava/util/ArrayList;

    .line 78
    const-string v0, "--%s\r\nContent-Disposition: form-data;name=\"%s\";filename=\"%s\"\r\nContent-Type: %s\r\n\r\n"

    iput-object v0, p0, Lcom/qiniu/utils/MultipartEntity;->fileTpl:Ljava/lang/String;

    .line 21
    const/16 v0, 0x20

    invoke-static {v0}, Lcom/qiniu/utils/MultipartEntity;->getRandomString(I)Ljava/lang/String;

    move-result-object v0

    iput-object v0, p0, Lcom/qiniu/utils/MultipartEntity;->mBoundary:Ljava/lang/String;

    .line 22
    new-instance v0, Lorg/apache/http/message/BasicHeader;

    const-string v1, "Content-Type"

    new-instance v2, Ljava/lang/StringBuilder;

    invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V

    const-string v3, "multipart/form-data; boundary="

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    iget-object v3, p0, Lcom/qiniu/utils/MultipartEntity;->mBoundary:Ljava/lang/String;

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    invoke-direct {v0, v1, v2}, Lorg/apache/http/message/BasicHeader;-><init>(Ljava/lang/String;Ljava/lang/String;)V

    iput-object v0, p0, Lcom/qiniu/utils/MultipartEntity;->contentType:Lorg/apache/http/Header;

    .line 23
    return-void
.end method

.method static synthetic access$000(Lcom/qiniu/utils/MultipartEntity;)Ljava/lang/String;
    .registers 2
    .param p0, "x0"    # Lcom/qiniu/utils/MultipartEntity;

    .prologue
    .line 12
    iget-object v0, p0, Lcom/qiniu/utils/MultipartEntity;->fileTpl:Ljava/lang/String;

    return-object v0
.end method

.method static synthetic access$100(Lcom/qiniu/utils/MultipartEntity;)Ljava/lang/String;
    .registers 2
    .param p0, "x0"    # Lcom/qiniu/utils/MultipartEntity;

    .prologue
    .line 12
    iget-object v0, p0, Lcom/qiniu/utils/MultipartEntity;->mBoundary:Ljava/lang/String;

    return-object v0
.end method

.method static synthetic access$200(Lcom/qiniu/utils/MultipartEntity;)J
    .registers 3
    .param p0, "x0"    # Lcom/qiniu/utils/MultipartEntity;

    .prologue
    .line 12
    iget-wide v0, p0, Lcom/qiniu/utils/MultipartEntity;->writed:J

    return-wide v0
.end method

.method static synthetic access$202(Lcom/qiniu/utils/MultipartEntity;J)J
    .registers 4
    .param p0, "x0"    # Lcom/qiniu/utils/MultipartEntity;
    .param p1, "x1"    # J

    .prologue
    .line 12
    iput-wide p1, p0, Lcom/qiniu/utils/MultipartEntity;->writed:J

    return-wide p1
.end method

.method static synthetic access$300(Lcom/qiniu/utils/MultipartEntity;)Lcom/qiniu/utils/IOnProcess;
    .registers 2
    .param p0, "x0"    # Lcom/qiniu/utils/MultipartEntity;

    .prologue
    .line 12
    iget-object v0, p0, Lcom/qiniu/utils/MultipartEntity;->mNotify:Lcom/qiniu/utils/IOnProcess;

    return-object v0
.end method

.method private static getRandomString(I)Ljava/lang/String;
    .registers 7
    .param p0, "length"    # I

    .prologue
    .line 134
    const-string v0, "abcdefghijklmnopqrstuvwxyz0123456789"

    .line 135
    .local v0, "base":Ljava/lang/String;
    new-instance v3, Ljava/util/Random;

    invoke-direct {v3}, Ljava/util/Random;-><init>()V

    .line 136
    .local v3, "random":Ljava/util/Random;
    new-instance v4, Ljava/lang/StringBuilder;

    invoke-direct {v4}, Ljava/lang/StringBuilder;-><init>()V

    .line 137
    .local v4, "sb":Ljava/lang/StringBuilder;
    const/4 v1, 0x0

    .local v1, "i":I
    :goto_d
    if-ge v1, p0, :cond_21

    .line 138
    invoke-virtual {v0}, Ljava/lang/String;->length()I

    move-result v5

    invoke-virtual {v3, v5}, Ljava/util/Random;->nextInt(I)I

    move-result v2

    .line 139
    .local v2, "number":I
    invoke-virtual {v0, v2}, Ljava/lang/String;->charAt(I)C

    move-result v5

    invoke-virtual {v4, v5}, Ljava/lang/StringBuilder;->append(C)Ljava/lang/StringBuilder;

    .line 137
    add-int/lit8 v1, v1, 0x1

    goto :goto_d

    .line 141
    .end local v2    # "number":I
    :cond_21
    invoke-virtual {v4}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v5

    return-object v5
.end method


# virtual methods
.method public addField(Ljava/lang/String;Ljava/lang/String;)V
    .registers 8
    .param p1, "key"    # Ljava/lang/String;
    .param p2, "value"    # Ljava/lang/String;

    .prologue
    .line 26
    const-string v0, "--%s\r\nContent-Disposition: form-data; name=\"%s\"\r\n\r\n%s\r\n"

    .line 27
    .local v0, "tmp":Ljava/lang/String;
    iget-object v1, p0, Lcom/qiniu/utils/MultipartEntity;->mData:Ljava/lang/StringBuffer;

    const/4 v2, 0x3

    new-array v2, v2, [Ljava/lang/Object;

    const/4 v3, 0x0

    iget-object v4, p0, Lcom/qiniu/utils/MultipartEntity;->mBoundary:Ljava/lang/String;

    aput-object v4, v2, v3

    const/4 v3, 0x1

    aput-object p1, v2, v3

    const/4 v3, 0x2

    aput-object p2, v2, v3

    invoke-static {v0, v2}, Ljava/lang/String;->format(Ljava/lang/String;[Ljava/lang/Object;)Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v1, v2}, Ljava/lang/StringBuffer;->append(Ljava/lang/String;)Ljava/lang/StringBuffer;

    .line 28
    return-void
.end method

.method public addFile(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/qiniu/utils/InputStreamAt;)V
    .registers 12
    .param p1, "field"    # Ljava/lang/String;
    .param p2, "contentType"    # Ljava/lang/String;
    .param p3, "fileName"    # Ljava/lang/String;
    .param p4, "isa"    # Lcom/qiniu/utils/InputStreamAt;

    .prologue
    .line 31
    iget-object v6, p0, Lcom/qiniu/utils/MultipartEntity;->mFiles:Ljava/util/ArrayList;

    new-instance v0, Lcom/qiniu/utils/MultipartEntity$FileInfo;

    move-object v1, p0

    move-object v2, p1

    move-object v3, p2

    move-object v4, p3

    move-object v5, p4

    invoke-direct/range {v0 .. v5}, Lcom/qiniu/utils/MultipartEntity$FileInfo;-><init>(Lcom/qiniu/utils/MultipartEntity;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Lcom/qiniu/utils/InputStreamAt;)V

    invoke-virtual {v6, v0}, Ljava/util/ArrayList;->add(Ljava/lang/Object;)Z

    .line 32
    return-void
.end method

.method public getContent()Ljava/io/InputStream;
    .registers 2
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;,
            Ljava/lang/IllegalStateException;
        }
    .end annotation

    .prologue
    .line 53
    const/4 v0, 0x0

    return-object v0
.end method

.method public getContentLength()J
    .registers 9

    .prologue
    .line 41
    iget-wide v4, p0, Lcom/qiniu/utils/MultipartEntity;->mContentLength:J

    const-wide/16 v6, 0x0

    cmp-long v1, v4, v6

    if-lez v1, :cond_b

    iget-wide v2, p0, Lcom/qiniu/utils/MultipartEntity;->mContentLength:J

    .line 48
    :goto_a
    return-wide v2

    .line 42
    :cond_b
    iget-object v1, p0, Lcom/qiniu/utils/MultipartEntity;->mData:Ljava/lang/StringBuffer;

    invoke-virtual {v1}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v1

    invoke-virtual {v1}, Ljava/lang/String;->getBytes()[B

    move-result-object v1

    array-length v1, v1

    int-to-long v2, v1

    .line 43
    .local v2, "len":J
    iget-object v1, p0, Lcom/qiniu/utils/MultipartEntity;->mFiles:Ljava/util/ArrayList;

    invoke-virtual {v1}, Ljava/util/ArrayList;->iterator()Ljava/util/Iterator;

    move-result-object v1

    :goto_1d
    invoke-interface {v1}, Ljava/util/Iterator;->hasNext()Z

    move-result v4

    if-eqz v4, :cond_2f

    invoke-interface {v1}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v0

    check-cast v0, Lcom/qiniu/utils/MultipartEntity$FileInfo;

    .line 44
    .local v0, "fi":Lcom/qiniu/utils/MultipartEntity$FileInfo;
    invoke-virtual {v0}, Lcom/qiniu/utils/MultipartEntity$FileInfo;->length()J

    move-result-wide v4

    add-long/2addr v2, v4

    .line 45
    goto :goto_1d

    .line 46
    .end local v0    # "fi":Lcom/qiniu/utils/MultipartEntity$FileInfo;
    :cond_2f
    iget-object v1, p0, Lcom/qiniu/utils/MultipartEntity;->mBoundary:Ljava/lang/String;

    invoke-virtual {v1}, Ljava/lang/String;->length()I

    move-result v1

    add-int/lit8 v1, v1, 0x6

    int-to-long v4, v1

    add-long/2addr v2, v4

    .line 47
    iput-wide v2, p0, Lcom/qiniu/utils/MultipartEntity;->mContentLength:J

    goto :goto_a
.end method

.method public isRepeatable()Z
    .registers 2

    .prologue
    .line 36
    const/4 v0, 0x0

    return v0
.end method

.method public isStreaming()Z
    .registers 2

    .prologue
    .line 75
    const/4 v0, 0x0

    return v0
.end method

.method public setProcessNotify(Lcom/qiniu/utils/IOnProcess;)V
    .registers 2
    .param p1, "ret"    # Lcom/qiniu/utils/IOnProcess;

    .prologue
    .line 81
    iput-object p1, p0, Lcom/qiniu/utils/MultipartEntity;->mNotify:Lcom/qiniu/utils/IOnProcess;

    .line 82
    return-void
.end method

.method public writeTo(Ljava/io/OutputStream;)V
    .registers 10
    .param p1, "outputStream"    # Ljava/io/OutputStream;
    .annotation system Ldalvik/annotation/Throws;
        value = {
            Ljava/io/IOException;
        }
    .end annotation

    .prologue
    .line 58
    iget-object v2, p0, Lcom/qiniu/utils/MultipartEntity;->mData:Ljava/lang/StringBuffer;

    invoke-virtual {v2}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/String;->getBytes()[B

    move-result-object v2

    invoke-virtual {p1, v2}, Ljava/io/OutputStream;->write([B)V

    .line 59
    invoke-virtual {p1}, Ljava/io/OutputStream;->flush()V

    .line 60
    iget-wide v2, p0, Lcom/qiniu/utils/MultipartEntity;->writed:J

    iget-object v4, p0, Lcom/qiniu/utils/MultipartEntity;->mData:Ljava/lang/StringBuffer;

    invoke-virtual {v4}, Ljava/lang/StringBuffer;->toString()Ljava/lang/String;

    move-result-object v4

    invoke-virtual {v4}, Ljava/lang/String;->getBytes()[B

    move-result-object v4

    array-length v4, v4

    int-to-long v4, v4

    add-long/2addr v2, v4

    iput-wide v2, p0, Lcom/qiniu/utils/MultipartEntity;->writed:J

    .line 61
    iget-object v2, p0, Lcom/qiniu/utils/MultipartEntity;->mNotify:Lcom/qiniu/utils/IOnProcess;

    if-eqz v2, :cond_30

    iget-object v2, p0, Lcom/qiniu/utils/MultipartEntity;->mNotify:Lcom/qiniu/utils/IOnProcess;

    iget-wide v4, p0, Lcom/qiniu/utils/MultipartEntity;->writed:J

    invoke-virtual {p0}, Lcom/qiniu/utils/MultipartEntity;->getContentLength()J

    move-result-wide v6

    invoke-interface {v2, v4, v5, v6, v7}, Lcom/qiniu/utils/IOnProcess;->onProcess(JJ)V

    .line 62
    :cond_30
    iget-object v2, p0, Lcom/qiniu/utils/MultipartEntity;->mFiles:Ljava/util/ArrayList;

    invoke-virtual {v2}, Ljava/util/ArrayList;->iterator()Ljava/util/Iterator;

    move-result-object v2

    :goto_36
    invoke-interface {v2}, Ljava/util/Iterator;->hasNext()Z

    move-result v3

    if-eqz v3, :cond_46

    invoke-interface {v2}, Ljava/util/Iterator;->next()Ljava/lang/Object;

    move-result-object v1

    check-cast v1, Lcom/qiniu/utils/MultipartEntity$FileInfo;

    .line 63
    .local v1, "i":Lcom/qiniu/utils/MultipartEntity$FileInfo;
    invoke-virtual {v1, p1}, Lcom/qiniu/utils/MultipartEntity$FileInfo;->writeTo(Ljava/io/OutputStream;)V

    goto :goto_36

    .line 65
    .end local v1    # "i":Lcom/qiniu/utils/MultipartEntity$FileInfo;
    :cond_46
    new-instance v2, Ljava/lang/StringBuilder;

    invoke-direct {v2}, Ljava/lang/StringBuilder;-><init>()V

    const-string v3, "--"

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    iget-object v3, p0, Lcom/qiniu/utils/MultipartEntity;->mBoundary:Ljava/lang/String;

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    const-string v3, "--\r\n"

    invoke-virtual {v2, v3}, Ljava/lang/StringBuilder;->append(Ljava/lang/String;)Ljava/lang/StringBuilder;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/StringBuilder;->toString()Ljava/lang/String;

    move-result-object v2

    invoke-virtual {v2}, Ljava/lang/String;->getBytes()[B

    move-result-object v0

    .line 66
    .local v0, "data":[B
    invoke-virtual {p1, v0}, Ljava/io/OutputStream;->write([B)V

    .line 67
    invoke-virtual {p1}, Ljava/io/OutputStream;->flush()V

    .line 68
    iget-wide v2, p0, Lcom/qiniu/utils/MultipartEntity;->writed:J

    array-length v4, v0

    int-to-long v4, v4

    add-long/2addr v2, v4

    iput-wide v2, p0, Lcom/qiniu/utils/MultipartEntity;->writed:J

    .line 69
    iget-object v2, p0, Lcom/qiniu/utils/MultipartEntity;->mNotify:Lcom/qiniu/utils/IOnProcess;

    if-eqz v2, :cond_81

    iget-object v2, p0, Lcom/qiniu/utils/MultipartEntity;->mNotify:Lcom/qiniu/utils/IOnProcess;

    iget-wide v4, p0, Lcom/qiniu/utils/MultipartEntity;->writed:J

    invoke-virtual {p0}, Lcom/qiniu/utils/MultipartEntity;->getContentLength()J

    move-result-wide v6

    invoke-interface {v2, v4, v5, v6, v7}, Lcom/qiniu/utils/IOnProcess;->onProcess(JJ)V

    .line 70
    :cond_81
    invoke-virtual {p1}, Ljava/io/OutputStream;->close()V

    .line 71
    return-void
.end method
